/**
 * 修改个人用户页面js
 * Created by zhangsi on 2015/10/13.
 */
var userAdd = new XFApp.client();
XFApp.client.prototype.add = {
    isSubmitting : false,
    successCode : 10000,
    deptList : {},
    urlItems : {
        saveURL : basePath +"/user/saveOrUpdate",
        homeUrl : basePath + "/cms"
    },
    saveOrUpdate : function(){
        var _this = this;
        $.ajax( {
            url:this.urlItems.saveURL,
            data:$('#editForm').serialize(),
            type:'post',
            cache:false,
            dataType:'json',
            success:function(data) {
                if(data.code == _this.successCode){
                    webDialogUtil.callbackConfrimAlert(data.msg, function(){window.location = userAdd.add.urlItems.homeUrl});
                }else{
                    webDialogUtil.simple(data.msg);
                }
            },
            error : function() {
                webDialogUtil.simpleAlert("操作失败!");
            }
        });
    },
    formValidate : function(){
        $('#editForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                username: {
                    group: '.col-lg-4',
                    validators: {
                        notEmpty: {message: '登陆用户名不能为空'}
                    }
                },
                realName: {
                    group: '.col-lg-4',
                    validators: {
                        notEmpty: {message: '真实姓名不能为空'}
                    }
                },
                email: {
                    group: '.col-lg-4',
                    validators: {
                        emailAddress: {message: '邮箱地址不正确'}
                    }
                }

            }
        });
    },
    event : function(){
        $("#submitBtn").on("click",function(){
            $('#editForm').bootstrapValidator('validate');
            if($('#editForm').data('bootstrapValidator').isValid()){
                userAdd.add.saveOrUpdate();
            }
        });
        //运单表单验证
        this.formValidate();
    }
}
$(function(){
    userAdd.add.event();
});
